<template>
  <div>
    <div class="app-container" v-if="div===1">
      <div style="background-color: white;padding: 10px 10px 10px 10px">
        <el-form @submit.native.prevent :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch"
                 label-width="68px">
          <el-form-item label="搜索：" prop="schoolName" style="margin-bottom: 0">
            <el-input
              v-model="queryParams.schoolName"
              placeholder="请输入学校名称"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div style="background-color: white;margin-top: 10px;padding: 20px">
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              endicon="el-icon-plus"
              size="mini"
              @click="returnview"
              v-hasPermi="['patrol:form:add']"
            >返回
            </el-button>
          </el-col>
<!--          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
        </el-row>

        <el-table v-loading="loading" :data="formList" :header-cell-style="{background:'#E3E3E3'}">
          <el-table-column label="序号" align="center" prop="userId">
            <template slot-scope="scope">
              {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
            </template>
          </el-table-column>
          <el-table-column label="单位名称" align="center" prop="schoolName"/>
          <el-table-column label="填报日期" align="center" prop="fillTime">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.fillTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="截至日期" align="center" prop="fillTimeLimit">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.fillTimeLimit) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="填报情况" align="center">
            <template #default="scope">
              <span v-if="scope.row.fillType===1" style="color:#07A387 ">已填</span>
              <span v-else style="color:#E94242 ">未填</span>
              <span v-if="new Date(scope.row.fillTimeLimit).getTime()<new Date(scope.row.fillTime)"
                    style="color:#07A387 "><span style="color: red">
                (超时)
              </span></span>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="showform(scope.row.id)"
              >查看填报结果
              </el-button>
              <!--              <el-button
                              size="mini"
                              type="text"
                              @click="viewformdetails(true,scope.row.id)"
                              v-hasPermi="['patrol:form:edit']"
                            >填报
                            </el-button>-->
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </div>
    </div>
  </div>
</template>

<script>
import {listFilling} from "@/api/patrol/form";

export default {
  name: "viewschool",
  data() {
    return {
      div: 1,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 单表格数据
      formList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        schoolName: null,
        formId: this.$route.params && this.$route.params.id
      },
    };
  },
  created() {
    this.getList();
    if ((this.$route.params && this.$route.params.id) == null) {
      this.$router.push("/form/index");
    }
  },
  methods: {
    viewformdetails(is, formdataid) {
      this.$router.push({path: "/form/see/" + (is ? "fillin" : "check"), query: {formdataid: formdataid}});
    },
    /** 查询单列表 */
    getList() {
      if (this.$route.params && this.$route.params.id == null)
        return;
      this.loading = true;
      listFilling(this.queryParams).then(response => {
        this.formList = response.rows;
        this.total = response.total;
        this.loading = false;
        console.log(this.formList)
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        formName: null,
        createTime: null,
        createBy: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    returnview() {
      this.$router.push("/form/index");
    },
    showform(formdataid) {
      this.$router.push({path: "/form/see/" + "check", query: {formdataid: formdataid,source: false}});
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateForm(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addForm(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除单编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        closeOnClickModal: false,
        type: "warning"
      }).then(function () {
        return delForm(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有单数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        closeOnClickModal: false,
        type: "warning"
      }).then(function () {
        return exportForm(queryParams);
      }).then(response => {
        this.download(response.msg);
      })
    }
  }
};
</script>

<style scoped>
.app-container {
  background-color: #edf1f2;
  padding: 10px;
  min-height: calc(100vh - 35px)
}

::v-deep.pagination-container .el-pagination {
  text-align: center;
  position: sticky;
}

::v-deep.el-form-item {
  margin-bottom: 0;
}
</style>
